package cn.edu.scau.cmi.huangxiyan.composite;

import java.util.HashSet;
import java.util.Set;

public class SafeComposite extends SafeComponent {
	private String name = "";
	private Set<SafeComponent> children = new HashSet<SafeComponent>();
	private SafeComposite parent = null;

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setChildren(Set<SafeComponent> children) {
		this.children = children;
	}

	public Set<SafeComponent> getChildren() {
		return children;
	}

	public void addChild(SafeComponent child) {
		children.add(child);
	}

	public void removeChild(SafeComponent child) {
		children.remove(child);
	}

	public void setParent(SafeComposite parent) {
		this.parent = parent;
	}

	@Override
	public SafeComposite getParent() {
		return this.parent;
	}

	@Override
	public String doSomething() {
		return "我是安全性组合模式中的组合组件";
	}

	@Override
	public int hashCode() {
		return this.getName().hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		SafeComposite composite = (SafeComposite) obj;
		if (this.getName().equals(composite.getName())) {
			return true;
		}
		return false;
	}

}
